package wei.xinya.pattern.structural.Proxy.dynamicProxy;

import java.lang.reflect.Proxy;

public class JdkProxyFactory {
    public static Object getProxy(Object target) {
        // 目标类的类加载
        ClassLoader classLoader = target.getClass().getClassLoader();
        // 代理需要实现的接口，可指定多个
        Class<?>[] interfaces = target.getClass().getInterfaces();
        // 代理对象对应的自定义 InvocationHandler
        MyInvocationHandler invocationHandler = new MyInvocationHandler(target);

        return Proxy.newProxyInstance(classLoader, interfaces, invocationHandler);
    }
}
